home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent2 / gaplib.lha / GAPLib_Beta / include / GAP.h next >
C/C++ Source or Header  |  1999-01-27  |  5KB  |  132 lines

  1. /*
  2.  * GAP-Lib (C)1998 Peter Bengtsson
  3.  * The Genetic Algorithm Programming Library.
  4.  *
  5.  */
  6.  
  7. #ifndef    __GAP_H__
  8. #define    __GAP_H__
  9.  
  10. #ifndef    TAG_DONE    /* This should be defined if tags are already defined. */
  11.  
  12. typedef    long    Tag;
  13. typedef    unsigned long IPTR;
  14.  
  15. struct TagItem    {
  16.     Tag    ti_Tag;
  17.     IPTR    ti_Data;
  18. };
  19.  
  20. #define    TAG_DONE        (0L)
  21. #define  TAG_END     TAG_DONE
  22. #define    TAG_IGNORE    (1L)
  23. #define    TAG_MORE        (2L)
  24.  
  25. #define    TAG_DUMMY    (64L)
  26.  
  27. #endif
  28.  
  29. #ifndef    TRUE
  30. #define    TRUE    (~0)
  31. #define    FALSE    (0)
  32. #endif
  33.  
  34. #define    GAP_RAND_MAX    0x7ffffffd
  35.  
  36. /* Tags for CreatePopulation.
  37.  *
  38.  */
  39.  
  40. #define    POP_Init            (TAG_DUMMY+0x01)    /* Initialization function. */
  41. #define    POP_Destruct    (TAG_DUMMY+0x02)    /* Destructor function. */
  42. #define    POP_Cache        (TAG_DUMMY+0x03)    /* Cache? Defaults to TRUE. */
  43.  
  44. /* Tags for Evolve(). These define different parameters of the evolution
  45.  * of the Polyphant population.
  46.  */
  47.  
  48. #define    EVL_Evaluator     (TAG_DUMMY+0x01)    /* Fitness function, _REQUIRED_ */
  49. #define    EVL_Mutator         (TAG_DUMMY+0x02)    /* Mutator function */
  50. #define    EVL_Crosser         (TAG_DUMMY+0x03)    /* Crossover function */
  51. #define    EVL_Elite         (TAG_DUMMY+0x04)    /* No. of Elite individuals to copy without modification */
  52. #define    EVL_Dump             (TAG_DUMMY+0x05)    /* Dump the worst individuals */
  53. #define    EVL_Select         (TAG_DUMMY+0x06)    /* Select type */
  54. #define    EVL_Stats         (TAG_DUMMY+0x07)    /* Generate statistics  (Defaults to TRUE) */
  55. #define    EVL_PreMutate     (TAG_DUMMY+0x08)    /* Mutate before generating new individuals (Defaults to FALSE) */
  56. #define    EVL_Newbies         (TAG_DUMMY+0x09)    /* No. of new individuals to generate. */
  57. #define    EVL_Flags         (TAG_DUMMY+0x0A)    /* Mode of operation Flags */
  58. #define    EVL_Mensurator     (TAG_DUMMY+0x0B)    /* Measures the distance 'twixt individuals */
  59. #define    EVL_Crowding     (TAG_DUMMY+0x0C)    /* Use crowding replacement */
  60. #define    EVL_InitDumped     (TAG_DUMMY+0x0D)    /* If EVL_Dump>0, re-initialize dumped individuals. */
  61. #define    EVL_EraseBest     (TAG_DUMMY+0x0E)    /* If EVL_Newbies>0, replace the best individuals. */
  62. #define    EVL_Transcriber (TAG_DUMMY+0x0F)    /* Transcription function. */
  63. #define    EVL_Thermostat     (TAG_DUMMY+0x10)    /* Regulates selection 'temperature'. */
  64.  
  65. /* For EVL_Select */
  66.  
  67. #define    DRANDOM        1L        /* Double Random */
  68. #define    FITPROP        2L        /* Fitness Proportionate */
  69. #define    SIGMA            3L        /* Sigma Scaled Selection */
  70. #define    TOURNAMENT    4L        /* Tournament Selection */
  71. #define    INORDER        5L        /* Sorted in order of fitness */
  72. #define    TEMPERATURE    6L        /* Temperature-dependant selection eg. Boltzmann */
  73. #define    UNIVERSAL    7L        /* Stochastic Universal selection */
  74.  
  75. /* For POP_Init */
  76.  
  77. #define    ZERO_INIT    0L        /* Zeroed bits */
  78. #define    RAND_INIT    1L        /* Random bits */
  79.  
  80. /* For EVL_Flags */
  81.  
  82. #define    FLG_InitDumped            (1L<<0)
  83. #define    FLG_EraseBest            (1L<<1)
  84. #define    FLG_Crowding            (1L<<2)
  85. #define    FLG_Statistics            (1L<<3)
  86.  
  87. #define    UnitedKingdomFlag    (1L<<31)
  88.  
  89. /* Structures */
  90.  
  91. struct Popstat {
  92.     double    AverageFitness;        /* Average fitness of population. */
  93.     double    MedianFitness;            /* Median fitness of the population. */
  94.     double    TypeFitness;            /* Type fitness value (Most common) */
  95.     long        TypeCount;                /* Countvalue for type fitness */
  96.     double    StdDeviation;            /* Standard deviation */
  97.     double    MaxFitness;                /* Fitness of the fittest individual.  */
  98.     double    MinFitness;                /* Fitness of the least fit individual. */
  99.     void        *Max;                        /* Pointer to the fittest individual. */
  100.     long        Generation;
  101. };
  102.  
  103. struct Population {
  104.     long     NumPolys;
  105.     long     Generation;
  106.     long     Flags;
  107.     struct Popstat Stat;
  108.     long     Bytes;
  109.     void    *Polys;
  110.     void    *Magic;
  111. };
  112.  
  113. extern int                         EnterGAP(int);
  114. extern void                      Crossover(void *Ind1,void *Ind2,const long int At,const long int Size);
  115. extern void                      Flip(void *Individual,const long int At);
  116. extern int                           Testbit(void *Individual,long int At);
  117. extern void                         InitRand(const long int);
  118. extern unsigned long int     Rnd(const long int Max);
  119. extern double                     InRand(const double From,const double To);
  120. extern double                     GaussRand(const double My,const double Sigma);
  121. extern double                     PoissonRand(const double My);
  122. extern struct Population    *CreatePopulation(const long int NumIndividuals,const long int Size,struct TagItem *);
  123. extern struct Population    *CreatePopulationT(const long int NumIndividuals,const long int Size,...);
  124. extern struct Population    *Evolve(struct Population *OldPop,struct TagItem *);
  125. extern struct Population    *EvolveT(struct Population *,...); /* Varargs interface to Evolve() */
  126. extern void                         DeletePopulation(struct Population *Pop);
  127. extern void                        *PopMember(struct Population *,const long int);
  128. extern double                     IRange(const unsigned long int,const double,const double);
  129. extern unsigned long int     HammingDist(void *,void *,const int);
  130.  
  131. #endif
  132.